function editP(pId, pName, pType, pIdtype, pIdno, pBirthday,phone) {
	$("#pId").val(pId);
	$("#pName").val(pName);
	$("#pType").val(pType);
	$("#pIdtype").val(pIdtype);
	$("#pIdno").val(pIdno);
	$("#pBirthday").val(pBirthday);
	$("#psgPhone").val(phone);
}

function subDataForm1() {
	var pId = $("#pId").val();
	var pName = $("#pName").val();
	var pType = $("#pType").val();
	var pIdtype = $("#pIdtype").val();
	var pIdno = $("#pIdno").val();
	var pBirthday = $("#pBirthday").val();
	var psgPhone = $("#psgPhone").val();
	var psgTable = document.getElementById("psgTable");
	
	//证件类型是身份证
	if (pIdtype == '00') {
		if(IdCardValidate(pIdno)) {
			pBirthday = getBirthdatByIdNo(pIdno);
			$("#pBirthday").val(pBirthday);
			$("#pIdno").removeClass("Validform_error");
			$("#vc2").removeClass("Validform_right Validform_wrong");
		} else {
			document.getElementById("vc2").innerHTML = "请输入正确的身份证号码！";
			$("#pIdno").addClass("Validform_error");
			$("#vc2").addClass("Validform_checktip Validform_wrong");
			return;
		}
	} else {
		$("#pBirthday").val(pBirthday);
		$("#pIdno").removeClass("Validform_error");
		$("#vc2").removeClass("Validform_right Validform_wrong");
	}
	$.ajax({
    	type:"post",//请求方式
    	url:"tc.do",//发送请求地址
    	data:{//发送的数据
    		m:"save_p",
    		pId:pId,
    		pName:pName,
    		pType:pType,
    		pIdtype:pIdtype,
    		pIdno:pIdno,
    		pBirthday:pBirthday,
    		psgPhone:psgPhone
    	},
    	dataType:"json",  
    	//请求成功后的回调函数有两个参数
    	success:function(data,textStatus){
    		if ('1' == data.result) {
    			//alert(data.resultdes);
    			alert("登机人信息保存成功");
    			if (data.pId != '' && data.pId != pId) {
    				addPsgTr(data.pId, pName, pType, pIdtype, pIdno, pBirthday,psgPhone);
    			} else if(data.pId != '' && data.pId == pId) {
    				var c = document.getElementById(data.pId);
	    			psgTable.deleteRow(c.rowIndex);
    				addPsgTr(data.pId, pName, pType, pIdtype, pIdno, pBirthday,psgPhone);
    			}
    			$("#vc1").removeClass("Validform_right Validform_loading");
    			$("#vc2").removeClass("Validform_right Validform_loading");
    			$("#vc3").removeClass("Validform_right Validform_loading");
    			var vc1 = document.getElementById("vc1");
    			var vc2 = document.getElementById("vc2");
    			var vc3 = document.getElementById("vc3");
    			vc1.innerHTML = "";
    			vc2.innerHTML = "";
    			vc3.innerHTML = "";
    			clearP();
    		} else {
    			alert(data.resultdes);
    		}
    	}
    });
}

function addPsgTr(pId, pName, pType,pIdtype,pIdno,pBirthday,psgPhone) {
	var psgTable = document.getElementById("psgTable");
	var newRow = psgTable.insertRow(psgTable.rows.length);
	newRow.id = pId;
	var c1 = newRow.insertCell(0);
	c1.innerHTML = pName;
	
	var c2 = newRow.insertCell(1);
	if (pType == '0') {
		c2.innerHTML = "成人";
	} else {
		c2.innerHTML = "儿童";
	}
	var c3 = newRow.insertCell(2);
	if (pIdtype == '00') {
		c3.innerHTML = "身份证";
	} else if(pIdtype == '01'){
		c3.innerHTML = "护照";
	}  else if(pIdtype == '02'){
		c3.innerHTML = "军官证";
	}  else if(pIdtype == '03'){
		c3.innerHTML = "回乡证";
	}  else if(pIdtype == '04'){
		c3.innerHTML = "台胞证";
	}  else if(pIdtype == '05'){
		c3.innerHTML = "港澳通行证";
	} else {
		c3.innerHTML = "其他证件";
	}
	var c4 = newRow.insertCell(3);
	c4.innerHTML = pIdno;
	var c5 = newRow.insertCell(4);
	c5.innerHTML = psgPhone;
	var c6 = newRow.insertCell(5);
	c6.innerHTML = "<a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"editP('"+pId+"','"+pName+"','"+pType+"','"+pIdtype+"','"+pIdno+"','"+pBirthday+"','"+psgPhone+"');\">" +
	"编辑</a>  |  <a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"deleteP(this,'"+pId+"');\">删除</a>";
}

function deleteP(c, pId) {
	if(confirm("是否删除此乘机人？")) {
		$.ajax({
	    	type:"post",//请求方式
	    	url:"tc.do",//发送请求地址
	    	data:{//发送的数据
	    		m:"del_p",
	    		pId:pId
	    	},
	    	dataType:"json",  
	    	//请求成功后的回调函数有两个参数
	    	success:function(data,textStatus){
	    		if ('1' == data.result) {
	    			var psgTable = document.getElementById("psgTable");
	    			psgTable.deleteRow(c.parentNode.parentNode.rowIndex);
	    		} else {
	    			alert(data.resultdes);
	    		}
	    	}
	    });
	}
}

function checkPhone() {
	var tPhoneZone = $("#tPhoneZone").val();
	var tPhone = $("#tPhone").val();
	var tExtension = $("#tExtension").val();
	if (tPhoneZone != '' && tPhone == '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tPhone").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}else if (tPhoneZone == '' && tPhone != '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tPhoneZone").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}else if (tExtension != '' && tPhone == '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tExtension").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}
}

//保存或更新联系人地址，提交数据
function subDataForm2() {
	var tId = $("#tId").val();
	var tName = $("#tName").val();
	var tProvince = $("#tProvince").val();
	if (tProvince == '请选择省份名') {
		document.getElementById("vc7").innerHTML = "请选择省份名！";
		$("#tProvince").addClass("Validform_error");
		$("#vc7").addClass("Validform_checktip Validform_wrong");
		return;
	} else {
		$("#tProvince").removeClass("Validform_error");
		$("#vc7").removeClass("Validform_right Validform_wrong");
	}
	var tCity = $("#tCity").val();
	var tArea = $("#tArea").val();
	var tStreet = $("#tStreet").val();
	var tPostcode = $("#tPostcode").val();
	var tPhoneZone = $("#tPhoneZone").val();
	var tPhone = $("#tPhone").val();
	var tExtension = $("#tExtension").val();
	var tContactPhone = $("#tContactPhone").val();
	var isDefault = $("#isDefault").val();
	var pDistrictCode = $("#tProvince").find("option:selected").attr("districtId");
	var cDistrictCode = $("#tCity").find("option:selected").attr("districtId");
	var districtCode = $("#tArea").find("option:selected").attr("districtId");
	var takeTable = document.getElementById("takeTable");
	if (tPhoneZone != '' && tPhone == '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tPhone").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}else if (tPhoneZone == '' && tPhone != '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tPhoneZone").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}else if (tExtension != '' && tPhone == '') {
		document.getElementById("vc6").innerHTML = "请输入有效的电话号码！";
		$("#tExtension").addClass("Validform_error");
		$("#vc6").addClass("Validform_checktip Validform_wrong");
		return;
	}
	
	$.ajax({
    	type:"post",//请求方式
    	url:"tc.do",//发送请求地址
    	data:{//发送的数据
    		m:"save_t",
    		tId:tId,
    		tName:tName,
    		tProvince:tProvince,
    		tCity:tCity,
    		tArea:tArea,
    		tStreet:tStreet,
    		tPostcode:tPostcode,
    		tPhoneZone:tPhoneZone,
    		tPhone:tPhone,
    		tExtension:tExtension,
    		tContactPhone:tContactPhone,
    		isDefault:isDefault,
    		districtCode:districtCode,
	        cDistrictCode:cDistrictCode,
	        pDistrictCode:pDistrictCode
    	},
    	dataType:"json",  
    	//请求成功后的回调函数有两个参数
    	success:function(data,textStatus){
    		if ('1' == data.result) {
    			alert("联系人地址保存成功!");
    			if (data.tId != '' && data.tId != tId) {
    				addTakeTr(data.tId, tName,tProvince,tCity,tStreet,tPostcode,tPhoneZone,tPhone,tExtension,tContactPhone,isDefault,districtCode,cDistrictCode,pDistrictCode);
    			} else if(data.tId != '' && data.tId == tId) {
    				var c = document.getElementById(data.tId);
    				takeTable.deleteRow(c.rowIndex);
    				addTakeTr(data.tId, tName,tProvince,tCity,tStreet,tPostcode,tPhoneZone,tPhone,tExtension,tContactPhone,isDefault,districtCode,cDistrictCode,pDistrictCode);
    			}
    			for (i = 4; i <= 9; i++) {
    				$("#vc"+i).removeClass("Validform_right Validform_loading");
    				document.getElementById("vc"+i).innerHTML = "";
    			}
    			clearT();
    		} else {
    			alert(data.resultdes);
    		}
    	}
    });
}

//常用投保人 保存数据
function subDataForm3(){
	var tId = $("#ttId").val();
	var tName = $("#ttName").val();
	var tProvince = $("#ttProvince").val();
	if (tProvince == '请选择省份名') {
		document.getElementById("vvc7").innerHTML = "请选择省份名！";
		$("#ttProvince").addClass("Validform_error");
		$("#vvc7").addClass("Validform_checktip Validform_wrong");
		return;
	} else {
		$("#ttProvince").removeClass("Validform_error");
		$("#vvc7").removeClass("Validform_right Validform_wrong");
	}
	var tCity = $("#ttCity").val();
	var tArea = $("#ttArea").val();
	var tStreet = $("#ttStreet").val();
	var tContactPhone = $("#ttContactPhone").val();
	var pDistrictCode = $("#ttProvince").find("option:selected").attr("districtId");
	var cDistrictCode = $("#ttCity").find("option:selected").attr("districtId");
	var districtCode = $("#ttArea").find("option:selected").attr("districtId");
	var appIdtype = $("#appIdtype").find("option:selected").attr("value");
	var appIdtypeName = $("#appIdtype").find("option:selected").text();
	var appIdNum = $("#appIdNum").val();
	var tEail = $("#tEail").val();
	var appSex = $('input:radio[name="appSex"]:checked').val();
	var takeTable = document.getElementById("ttakeTable");
	var birthday =  $("#birthday").val();;
	var appSexName = "";
	if(appSex=='1'){
		appSexName = '男';
	}else{
		appSexName ='女';
	}
	$.ajax({
    	type:"post",//请求方式
    	url:"insurance.do",//发送请求地址
    	data:{//发送的数据
    		m:"save_t",
    		tId:tId,
    		tName:tName,
    		tProvince:tProvince,
    		tCity:tCity,
    		tArea:tArea,
    		tStreet:tStreet,
    		tContactPhone:tContactPhone,
    		districtCode:districtCode,
	        cDistrictCode:cDistrictCode,
	        pDistrictCode:pDistrictCode,
	        appIdtype:appIdtype,
	        appIdNo:appIdNum,
	        tEail:tEail,
	        appSex:appSex,
	        isApp:"yes",
	        birthday:birthday
    	},
    	dataType:"json",  
    	//请求成功后的回调函数有两个参数
    	success:function(data,textStatus){
    		if ('1' == data.result) {
    			alert("投保人信息保存成功");
    			if (data.tId != '' && data.tId != tId) {
    				addTakeTrr(data.tId, tName,tProvince,tCity,tStreet,tContactPhone,appIdtypeName,appIdNum,tEail,appSexName);
    			} else if(data.tId != '' && data.tId == tId) {
    				var c = document.getElementById(data.tId);
    				takeTable.deleteRow(c.rowIndex);
    				addTakeTrr(data.tId, tName,tProvince,tCity,tStreet,tContactPhone,appIdtypeName,appIdNum,tEail,appSexName);
    			}
    			for (i = 3; i <= 9; i++) {
    				$("#vvc"+i).removeClass("Validform_right Validform_loading");
    				document.getElementById("vvc"+i).innerHTML = "";
    			}
    			clearTt();
    		} else {
    			alert(data.resultdes);
    		}
    	}
    });
}
	
//常用被保人 保存数据
function subDataForm4(){
	var tId = $("#tttId").val();
	var tName = $("#tttName").val();
	var tProvince = $("#tttProvince").val();
	if (tProvince == '请选择省份名') {
		document.getElementById("vvvc7").innerHTML = "请选择省份名！";
		$("#tttProvince").addClass("Validform_error");
		$("#vvvc7").addClass("Validform_checktip Validform_wrong");
		return;
	} else {
		$("#tttProvince").removeClass("Validform_error");
		$("#vvvc7").removeClass("Validform_right Validform_wrong");
	}
	var tCity = $("#tttCity").val();
	var tArea = $("#tttArea").val();
	var tStreet = $("#tttStreet").val();
	var tContactPhone = $("#tttContactPhone").val();
	var pDistrictCode = $("#tttProvince").find("option:selected").attr("districtId");
	var cDistrictCode = $("#tttCity").find("option:selected").attr("districtId");
	var districtCode = $("#tttArea").find("option:selected").attr("districtId");
	var appIdtype = $("#appdIdtype").find("option:selected").attr("value");
	var appIdtypeName = $("#appdIdtype").find("option:selected").text();
	var appIdNum = $("#appdIdNum").val();
	var pdBirthday = $("#pdBirthday").val();
	var recRelation = $("#recRelation").find("option:selected").attr("value");
	var recRelationName = $("#recRelation").find("option:selected").text();
	var appSex = $('input:radio[name="appdSex"]:checked').val();
	var applyName = $('input:radio[name="applyName"]:checked').val();
	if(applyName==undefined){
		applyName = "无";	}
	var takeTable = document.getElementById("tttakeTable");
	var appSexName = "";
	if(appSex=='1'){
		appSexName = '男';
	}else{
		appSexName ='女';
	}
	$.ajax({
    	type:"post",//请求方式
    	url:"insurance.do",//发送请求地址
    	data:{//发送的数据
    		m:"save_insurd",
    		tId:tId,
    		tName:tName,
    		tProvince:tProvince,
    		tCity:tCity,
    		tArea:tArea,
    		tStreet:tStreet,
    		tContactPhone:tContactPhone,
    		districtCode:districtCode,
	        cDistrictCode:cDistrictCode,
	        pDistrictCode:pDistrictCode,
	        appIdtype:appIdtype,
	        appIdNo:appIdNum,
	        pdBirthday:pdBirthday,
	        recRelation:recRelation,
	        appSex:appSex,
	        applyName:applyName,
	        isApp:"yes"
    	},
    	dataType:"json",  
    	//请求成功后的回调函数有两个参数
    	success:function(data,textStatus){
    		if ('1' == data.result) {
    			alert("被保人信息保存成功");
    			if (data.pId != '' && data.pId != tId) {
    				addTakeTrrr(data.pId, tName,tProvince,tCity,tStreet,recRelationName,applyName,appIdtypeName,appIdNum,tContactPhone,pdBirthday,appSexName);
    			} else if(data.pId != '' && data.pId== tId) {
    				var c = document.getElementById(data.pId);
    				takeTable.deleteRow(c.rowIndex);
    				addTakeTrrr(data.pId, tName,tProvince,tCity,tStreet,recRelationName,applyName,appIdtypeName,appIdNum,tContactPhone,pdBirthday,appSexName);
    			}
    			for (i = 3; i <= 8; i++) {
    				$("#vvvc"+i).removeClass("Validform_right Validform_loading");
    				document.getElementById("vvvc"+i).innerHTML = "";
    			}
    			clearTtt();
    		} else {
    			alert(data.resultdes);
    		}
    	}
    });
}


	function editT(tId,tName,tProvince,tCity,tStreet,tPostcode,tPhoneZone,tPhone,tExtension,tContactPhone,isDefault,districtId,cDistrictId,pDistrictId) {
		if(tName !="null"){
			$("#tName").val(tName);
		}
		if(tPostcode !="null"){
			$("#tPostcode").val(tPostcode);
		}
		if(tStreet != "null"){
			$("#tStreet").val(tStreet);
		}
		if(tContactPhone != "null"){
			$("#tContactPhone").val(tContactPhone);
		}
		$("#tId").val(tId);
		//$("#tProvince").val(tProvince);
//		$("#tProvince").change(areaMap.city($("#tProvince").val()));
		$("#tCity").val(tCity);
		$("#tPhoneZone").val(tPhoneZone);
		$("#tPhone").val(tPhone);
		$("#tExtension").val(tExtension);
		$("#isDefault").val(isDefault);

		if ('Y' == isDefault) {
			document.getElementById("isDefault").checked = true;
		} else {
			document.getElementById("isDefault").checked = false;
		}
		
		
		$("#tProvince option[districtId="+pDistrictId+"]").attr("selected", true);
		var districtCode = $("#tProvince").find("option:selected").attr("districtCode");
		
		$.ajax({  
			   type: "POST",   
			   url: "tc.do",
			   data:{
				    m:"queryCityRegion", 
				    districtGrade:"1",
					cDistrictId:cDistrictId,
					districtCode:districtCode
			   },
			   dataType:"json", 
			   async:false , 
			   success: function(data){
					   if(data.queryCity!=null && data.queryCity !=''){
						   $("#tCity").empty();
						   	var queryCity = data.queryCity;
					   		for(var i=0;i<queryCity.length;i++){
					   			$("#tCity").append("<option districtId='"+queryCity[i]["districtId"]+"' districtCode='"+queryCity[i]["districtCode"]+"' value='"+queryCity[i]["districtName"]+"'>"+queryCity[i]["districtName"]+"</option>");
					   		}
					   		$("#tCity option[districtId="+cDistrictId+"]").attr("selected", true);
					   	}else{
					   	 	$("#tCity").empty();
					   	}
				   
				   	
				   	if(data.queryArea != null && data.queryArea!=''){
				   		$("#tArea").empty();
				   		var queryArea = data.queryArea;
				   		for(var i=0;i<queryArea.length;i++){
				   			$("#tArea").append("<option districtId='"+queryArea[i]["districtId"]+"' districtCode='"+queryArea[i]["districtCode"]+"' value='"+queryArea[i]["districtName"]+"'>"+queryArea[i]["districtName"]+"</option>");
				   		}
				   		$("#tArea option[districtId="+districtId+"]").attr("selected", true);
				   	}else{
				   		$("#tArea").empty();
				   	}
				   
			   },
			   error:function(){
			   	   alert("error!");
			   }	 
		});
		
		
	}

	
	//编辑投保人信息
	function editTt(tId,tName,tSex,tProvince,tCity,tStreet,tEmail,tIdType,tIdNo,tContactPhone,districtId,cDistrictId,pDistrictId,birthday) {
		if(tName !="null"){
			$("#ttName").val(tName);
		}
		if(tEmail !="null"){
			$("#tEail").val(tEmail);
		}
		if(tStreet != "null"){
			$("#ttStreet").val(tStreet);
		}
		if(tContactPhone != "null"){
			$("#ttContactPhone").val(tContactPhone);
		}
		$("#birthday").val(birthday);
		if(tSex=='男'){
		$("#appSexM").attr("checked","checked");
			
		}else{
			$("#appSexF").attr("checked","checked");
		}
		$("#ttId").val(tId);
		$("#ttCity").val(tCity);
		$("#appIdtype option[value="+tIdType+"]").attr("selected", true);
		$("#appIdNum").val(tIdNo);
		$("#ttProvince option[districtId="+pDistrictId+"]").attr("selected", true);
		var districtCode = $("#ttProvince").find("option:selected").attr("districtCode");
		$.ajax({  
		   type: "post",   
		   url: "insurance.do",
		   data:{
			    m:"queryAdminiRegion", 
			    districtGrade:"1",
				cDistrictId:cDistrictId,
				districtCode:districtCode
		   },
		   dataType:"json", 
		   async:false , 
		   success: function(data){
				   if(data.queryCity!=null && data.queryCity !=''){
					   $("#ttCity").empty();
					   	var queryCity = data.queryCity;
				   		for(var i=0;i<queryCity.length;i++){
				   			$("#ttCity").append("<option districtId='"+queryCity[i]["districtId"]+"' districtCode='"+queryCity[i]["districtCode"]+"' value='"+queryCity[i]["districtName"]+"'>"+queryCity[i]["districtName"]+"</option>");
				   		}
				   		$("#ttCity option[districtId="+cDistrictId+"]").attr("selected", true);
				   	}else{
				   	 	$("#ttCity").empty();
				   	}
			   
			   	
			   	if(data.queryArea != null && data.queryArea!=''){
			   		$("#ttArea").empty();
			   		var queryArea = data.queryArea;
			   		for(var i=0;i<queryArea.length;i++){
			   			$("#ttArea").append("<option districtId='"+queryArea[i]["districtId"]+"' districtCode='"+queryArea[i]["districtCode"]+"' value='"+queryArea[i]["districtName"]+"'>"+queryArea[i]["districtName"]+"</option>");
			   		}
			   		$("#ttArea option[districtId="+districtId+"]").attr("selected", true);
			   	}else{
			   		$("#ttArea").empty();
			   	}
			   
		   },
		   error:function(){
		   	   alert("error!");
		   }	 
	});
	
	
}

	//编辑被保人信息
	function editTtt(tId,tName,tProvince,tCity,tStreet,relation,apply,tIdType,tIdNo,tContactPhone,birthday,tSex,districtId,cDistrictId,pDistrictId) {
		if(tName !="null"){
			$("#tttName").val(tName);
		}
		if(birthday !="null"){
			$("#pdBirthday").val(birthday);
		}
		if(tStreet != "null"){
			$("#tttStreet").val(tStreet);
		}
		if(tContactPhone != "null"){
			$("#tttContactPhone").val(tContactPhone);
		}
		
		if(tSex=='男'){
		$("#insurSexM").attr("checked","checked");
			
		}else{
			$("#insurSexF").attr("checked","checked");
		}
		var applyName = new Array();
		$('input[name=applyName]').each(function(key){
			applyName[key] = $(this).attr("value");
		});
		for(var i = 0 ;i<applyName.length;i++){
			if(apply==applyName[i]){
				$("input:radio[value='"+apply+"']").attr("checked","checked");
			}
		}
		$("#recRelation option[value="+relation+"]").attr("selected", true);
		$("#tttId").val(tId);
		$("#tttCity").val(tCity);
		$("#appdIdtype option[value="+tIdType+"]").attr("selected", true);
		$("#appdIdNum").val(tIdNo);
		$("#tttProvince option[districtId="+pDistrictId+"]").attr("selected", true);
		var districtCode = $("#tttProvince").find("option:selected").attr("districtCode");
		$.ajax({  
			   type: "post",   
			   url: "insurance.do",
			   data:{
				    m:"queryAdminiRegion", 
				    districtGrade:"1",
					cDistrictId:cDistrictId,
					districtCode:districtCode
		   },
		   dataType:"json", 
		   async:false , 
		   success: function(data){
				   if(data.queryCity!=null && data.queryCity !=''){
					   $("#tttCity").empty();
					   	var queryCity = data.queryCity;
				   		for(var i=0;i<queryCity.length;i++){
				   			$("#tttCity").append("<option districtId='"+queryCity[i]["districtId"]+"' districtCode='"+queryCity[i]["districtCode"]+"' value='"+queryCity[i]["districtName"]+"'>"+queryCity[i]["districtName"]+"</option>");
				   		}
				   		$("#tttCity option[districtId="+cDistrictId+"]").attr("selected", true);
				   	}else{
				   	 	$("#tttCity").empty();
				   	}
			   
			   	
			   	if(data.queryArea != null && data.queryArea!=''){
			   		$("#tttArea").empty();
			   		var queryArea = data.queryArea;
			   		for(var i=0;i<queryArea.length;i++){
			   			$("#tttArea").append("<option districtId='"+queryArea[i]["districtId"]+"' districtCode='"+queryArea[i]["districtCode"]+"' value='"+queryArea[i]["districtName"]+"'>"+queryArea[i]["districtName"]+"</option>");
			   		}
			   		$("#tttArea option[districtId="+districtId+"]").attr("selected", true);
			   	}else{
			   		$("#tttArea").empty();
			   	}
			   
		   },
		   error:function(){
		   	   alert("error!");
		   }	 
	});
	
	
}



function addTakeTr(tId,tName,tProvince,tCity,tStreet,tPostcode,tPhoneZone,tPhone,tExtension,tContactPhone,isDefault) {
	var takeTable = document.getElementById("takeTable");
	var newRow = takeTable.insertRow(takeTable.rows.length);
	newRow.id = tId;
	var c1 = newRow.insertCell(0);
	c1.innerHTML = tName;
	
	var c2 = newRow.insertCell(1);
	c2.innerHTML = tProvince +" " +tCity;
	
	var c3 = newRow.insertCell(2);
	c3.innerHTML = tStreet;
	
	var c4 = newRow.insertCell(3);
	c4.innerHTML = tPostcode;
	
	var c5 = newRow.insertCell(4);
	var c5Str = "";
	if (tPhoneZone != '') {
		c5Str += tPhoneZone+" - ";
	}
	if (tPhone != '') {
		c5Str += tPhone;
	}
	if (tExtension != '') {
		c5Str += " - " + tExtension;
	}
	if (tPhone != '' && tContactPhone != '') {
		c5Str += " / ";
	}
	c5Str += tContactPhone;
	c5.innerHTML = c5Str;
	
	var c6 = newRow.insertCell(5);
	if (isDefault == 'Y') {
		for (i = 1; i < takeTable.rows.length; i++) {
			takeTable.rows[i].cells[5].innerHTML = "";
		}
		c6.innerHTML = '默认地址';
	} else {
		c6.innerHTML = '';
	}
	var c7 = newRow.insertCell(6);
	c7.innerHTML = "<a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"editT('"+tId+"','"+tName+"','"+tProvince+"','"+tCity+"','"+tStreet+"','"
		+tPostcode+"','"+tPhoneZone+"','"+tPhone+"','"+tExtension+"','"+tContactPhone+"','"+isDefault+"');\">" +
	"编辑</a>  |  <a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"deleteT(this,'"+tId+"');\">删除</a>";
}
//添加一行 投保人中
function addTakeTrr(tId, tName,tProvince,tCity,tStreet,tContactPhone,appIdtype,appIdNum,tEail,appSex) {
	var takeTable = document.getElementById("ttakeTable");
	var newRow = takeTable.insertRow(takeTable.rows.length);
	newRow.id = tId;
	var c1 = newRow.insertCell(0);
	c1.innerHTML = tName;
	
	var c2 = newRow.insertCell(1);
	c2.innerHTML = tProvince +" " +tCity;
	
	var c3 = newRow.insertCell(2);
	c3.innerHTML = tStreet;
	
	var c4 = newRow.insertCell(3);
	c4.innerHTML = appIdtype+" " +appIdNum;
	
	var c5 = newRow.insertCell(4);
	
	c5.innerHTML = tContactPhone;
	
	var c6 = newRow.insertCell(5);
	
	c6.innerHTML = tEail;
	
	var c7 = newRow.insertCell(6);
	
	c7.innerHTML = appSex;
	
	var c8 = newRow.insertCell(7);
	c8.innerHTML = "<a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"editTt('"+tId+"','"+tName+"','"+appSex+"','"+tProvince+"','"+tCity+"','"
		+tStreet+"','"+tEail+"','"+appIdtype+"','"+appIdNum+"','"+tContactPhone+"');\">" +
	"编辑</a>  |  <a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"deleteTt(this,'"+tId+"');\">删除</a>";
}

//投保人中删除一行
function deleteTt(c, tId) {
	if(confirm("是否删除此投保人地址？")) {
		$.ajax({
	    	type:"post",//请求方式
	    	url:"insurance.do",//发送请求地址
	    	data:{//发送的数据
	    		m:"delete_apply",
	    		tId:tId
	    	},
	    	dataType:"json",  
	    	//请求成功后的回调函数有两个参数
	    	success:function(data,textStatus){
	    		if ('1' == data.result) {
	    			var psgTable = document.getElementById("ttakeTable");
	    			psgTable.deleteRow(c.parentNode.parentNode.rowIndex);
	    		} else {
	    			alert(data.resultdes);
	    		}
	    	}
	    });
	}
}
//被保人中删除一行
function deleteTtt(c, tId) {
	if(confirm("是否删除此联系人地址？")) {
		$.ajax({
	    	type:"post",//请求方式
	    	url:"insurance.do",//发送请求地址
	    	data:{//发送的数据
	    		m:"del_insurd",
	    		tId:tId
	    	},
	    	dataType:"json",  
	    	//请求成功后的回调函数有两个参数
	    	success:function(data,textStatus){
	    		if ('1' == data.result) {
	    			var psgTable = document.getElementById("tttakeTable");
	    			psgTable.deleteRow(c.parentNode.parentNode.rowIndex);
	    		} else {
	    			alert(data.resultdes);
	    		}
	    	}
	    });
	}
}

//添加一行 被保人中
function addTakeTrrr(tId, tName,tProvince,tCity,street,relation,apply,appIdtype,appIdNum,tContactPhone,birthday,appSex) {
	var takeTable = document.getElementById("tttakeTable");
	var newRow = takeTable.insertRow(takeTable.rows.length);
	newRow.id = tId;
	var c1 = newRow.insertCell(0);
	c1.innerHTML = tName;
	
	var c2 = newRow.insertCell(1);
	c2.innerHTML = tProvince +" " +tCity;
	
	var c3 = newRow.insertCell(2);
	c3.innerHTML = relation+" 投保人：" +apply;;
	
	var c4 = newRow.insertCell(3);
	c4.innerHTML = appIdtype+" " +appIdNum;
	
	var c5 = newRow.insertCell(4);
	
	c5.innerHTML = tContactPhone;
	
	var c6 = newRow.insertCell(5);
	
	c6.innerHTML = birthday;
	
	var c7 = newRow.insertCell(6);
	
	c7.innerHTML = appSex;
	
	var c8 = newRow.insertCell(7);
	c8.innerHTML = "<a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"editTtt('"+tId+"','"+tName+"','"+tProvince+"','"+tCity+"','"+street+"','"+relation+"','"
		+apply+"','"+appIdtype+"','"+appIdNum+"','"+tContactPhone+"','"+birthday+"','"+appSex+"');\">" +
	"编辑</a>  |  <a style=\"color:#0066CC;\" href=\"javascript:void(0);\" " +
	"onclick=\"deleteTtt(this,'"+tId+"');\">删除</a>";
}
function deleteT(c, tId) {
	if(confirm("是否删除此联系人地址？")) {
		$.ajax({
	    	type:"post",//请求方式
	    	url:"tc.do",//发送请求地址
	    	data:{//发送的数据
	    		m:"del_t",
	    		tId:tId
	    	},
	    	dataType:"json",  
	    	//请求成功后的回调函数有两个参数
	    	success:function(data,textStatus){
	    		if ('1' == data.result) {
	    			var psgTable = document.getElementById("takeTable");
	    			psgTable.deleteRow(c.parentNode.parentNode.rowIndex);
	    		} else {
	    			alert(data.resultdes);
	    		}
	    	}
	    });
	}
}

function changState(c) {
	if(c.checked == true) {
		c.value = "Y";
	} else {
		c.value = "N";
	}
}


function clearP() {
	$("#pId").val("");
	$("#pName").val("");
	//$("#pType").val("");
	//$("#pIdtype").val("");
	$("#pIdno").val("");
	$("#pBirthday").val("");
}

function clearT() {
	$("#tId").val("");
	$("#tName").val("");
	//$("#tProvince").val("");
	//$("#tCity").val("");
	$("#tStreet").val("");
	$("#tPostcode").val("");
	$("#tPhoneZone").val("");
	$("#tPhone").val("");
	$("#tExtension").val("");
	$("#tContactPhone").val("");
	$("#isDefault").val("");
}


//重置投保人
function clearTt() {
	$("#ttId").val("");
	$("#ttName").val("");
	$("#ttStreet").val("");
	$("#appIdNum").val("");
	$("#tEail").val("");
	$("#birthday").val("");
	$("#ttContactPhone").val("");
}

//重置被保人
function clearTtt() {
	$("#tttId").val("");
	$("#tttName").val("");
	$("#tttStreet").val("");
	$("#appdIdNum").val("");
	$("#pdBirthday").val("");
	$("#tttContactPhone").val("");
}

function setBirthdatByIdNo(c_value){
	var pIdtype = $("#pIdtype").val();
	if (pIdtype == '00') {
		if (IdCardValidate(c_value)) {
			$("#pBirthday").val(getBirthdatByIdNo(c_value));
			$("#pIdno").removeClass("Validform_error");
			$("#vc2").removeClass("Validform_right Validform_wrong");
			document.getElementById("vc2").innerHTML = "";
		} else {
			document.getElementById("vc2").innerHTML = "请输入正确的身份证号码！";
			$("#pIdno").addClass("Validform_error");
			$("#vc2").addClass("Validform_checktip Validform_wrong");
			return;
		}
	}

}

//获取行政区 投保人
function getAdminiRegion2(obj){
	    var districtId = "";
	  	var districtCode = "";
	  	if(obj == "1"){
	  		districtCode = $("#ttProvince").find("option:selected").attr("districtCode");
	  	}else if(obj == "2"){
	  		districtId = $("#ttCity").find("option:selected").attr("districtId");
	  		districtCode = $("#ttCity").find("option:selected").attr("districtCode");
	  	}
	  	$.ajax({   
			   type: "POST",   
			   url: "tc.do",
			   data:{
				    m:"queryAdminiRegion", 
				    districtGrade:"1",
					districtCode:districtCode,
					districtId:districtId
			   },
			   dataType:"json", 
			   async:false , 
			   success: function(data){
				   if(obj == "1"){
					   if(data.queryCity!=null && data.queryCity !=''){
						   $("#ttCity").empty();
						   
						   	var queryCity = data.queryCity;
					   		for(var i=0;i<queryCity.length;i++){
					   			$("#ttCity").append("<option districtId='"+queryCity[i]["districtId"]+"'districtCode='"+queryCity[i]["districtCode"]+"' value='"+queryCity[i]["districtName"]+"'>"+queryCity[i]["districtName"]+"</option>");
					   		}
					   	}else{
					   	 	$("#ttCity").empty();
					   	}
				   }
				   	
				   	if(data.queryArea != null && data.queryArea!=''){
				   		$("#ttArea").empty();
				   		var queryArea = data.queryArea;
				   		for(var i=0;i<queryArea.length;i++){
				   			$("#ttArea").append("<option districtId='"+queryArea[i]["districtId"]+"' districtCode='"+queryArea[i]["districtCode"]+"' value='"+queryArea[i]["districtName"]+"'>"+queryArea[i]["districtName"]+"</option>");
				   		}
				   	}else{
				   		$("#ttArea").empty();
				   	}
			   },
			   error:function(){
			   	   alert("error!");
			   }	 
		});
	}

//获取行政区 被保人
function getAdminiRegion3(obj){
	    var districtId = "";
	  	var districtCode = "";
	  	if(obj == "1"){
	  		districtCode = $("#tttProvince").find("option:selected").attr("districtCode");
	  	}else if(obj == "2"){
	  		districtId = $("#tttCity").find("option:selected").attr("districtId");
	  		districtCode = $("#tttCity").find("option:selected").attr("districtCode");
	  	}
	  	$.ajax({   
			   type: "POST",   
			   url: "tc.do",
			   data:{
				    m:"queryAdminiRegion", 
				    districtGrade:"1",
					districtCode:districtCode,
					districtId:districtId
			   },
			   dataType:"json", 
			   async:false , 
			   success: function(data){
				   if(obj == "1"){
					   if(data.queryCity!=null && data.queryCity !=''){
						   $("#tttCity").empty();
						   
						   	var queryCity = data.queryCity;
					   		for(var i=0;i<queryCity.length;i++){
					   			$("#tttCity").append("<option districtId='"+queryCity[i]["districtId"]+"'districtCode='"+queryCity[i]["districtCode"]+"' value='"+queryCity[i]["districtName"]+"'>"+queryCity[i]["districtName"]+"</option>");
					   		}
					   	}else{
					   	 	$("#tttCity").empty();
					   	}
				   }
				   	
				   	if(data.queryArea != null && data.queryArea!=''){
				   		$("#tttArea").empty();
				   		var queryArea = data.queryArea;
				   		for(var i=0;i<queryArea.length;i++){
				   			$("#tttArea").append("<option districtId='"+queryArea[i]["districtId"]+"' districtCode='"+queryArea[i]["districtCode"]+"' value='"+queryArea[i]["districtName"]+"'>"+queryArea[i]["districtName"]+"</option>");
				   		}
				   	}else{
				   		$("#tttArea").empty();
				   	}
			   },
			   error:function(){
			   	   alert("error!");
			   }	 
		});
	}

